<template>
  <div>
    <el-card>
      <el-col>
        <el-row>
          <el-button class="el-bottom" type="success" 
                     icon="el-icon-download" @click="getExcel">导出excel</el-button>
        </el-row>
      </el-col>
      <el-table :data="repairedList"
                border
                stripe>
        <el-table-column label="会议室名称"
                         prop="name">
        </el-table-column>
        <el-table-column label="报修原因"
                         prop="repairMessage">
        </el-table-column>
        <el-table-column label="维修完成">
          <template slot-scope="scope">
            <el-button type="primary"
                      icon="el-icon-set-up"
                      @click="updRepaired(scope.row.name)">
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
                     @current-change="handleCurrentChange"
                     :current-page="current"
                     layout="total, prev, pager, next"
                     :total="total">
      </el-pagination>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      repairedList: [],
      total: 0,
      current: 1,
    }
  },
  created(){
    this.getRepairedList()
  },
  methods:{
    async getRepairedList(){
      let param = this.$qs.stringify({
        current: this.current
      })
      let url = 'admin/repair/getRepair' + '?' + param
      const {data: res} = await this.$axios.get(url);
      if(res.code !== 200){
        return this.$message.error(res.message);
      }
      this.repairedList = res.data.records;
      this.total = res.data.total;
    },
    handleCurrentChange(newPage) {
      this.current = newPage
      this.getRepairedList()
    },
    async updRepaired(bname){
      let param = this.$qs.stringify({
        房间名: bname
      });
      let url = 'admin/repair/setRepair';
      const {data: res} = await this.$axios.post(url, param);
      if(res.code !== 200){
        return this.$message.error(res.data);
      }
      this.getRepairedList()
      return this.$message.success(res.data);
    },
    // async getExcel(){
    getExcel(){
      window.location.href = 'http://localhost:8000/admin/repair/export'
    // let url = 'admin/repair/export';
    // const {data: res} = await this.$axios.get(url);
    // let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
    // let fileUrl = window.URL.createObjectURL(blob);
    // window.location.href = fileUrl;
    return this.$message.success('导出成功！');
    }
  }
}
</script>

<style lang="less" scoped>
</style>